//
//  ZZCAlterPasswordController.m
//  ZZC-Finance
//
//  Created by mac on 2017/5/25.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCAlterPasswordController.h"
#import "ZZCMeController.h"
@interface ZZCAlterPasswordController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPasswordTextField;
@property (weak, nonatomic) IBOutlet UITextField *NewPasswordTextField;
@property (weak, nonatomic) IBOutlet UITextField *NewPasswordsTextField;

@end

@implementation ZZCAlterPasswordController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    [self.oldPasswordTextField becomeFirstResponder];
//    self.oldPasswordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
//    self.NewPasswordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
//    self.NewPasswordsTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.oldPasswordTextField.secureTextEntry = YES;
    self.NewPasswordTextField.secureTextEntry = YES;
    self.NewPasswordsTextField.secureTextEntry = YES;

}

//确定
- (IBAction)certainClick {
    ZZCLog(@"确认");
    if ([self.NewPasswordTextField.text isEqualToString:self.NewPasswordsTextField.text]) {
        NSString *token = ZZCNSUserDefaults(@"token");
        NSDictionary *dict = @{@"token":token,@"oldPassword":self.oldPasswordTextField.text,@"password":self.NewPasswordsTextField.text};
        NSString *sign = [ZZCRequest getSignWithDict:dict];
        sign = [NSString md5:[sign lowercaseString]];
        NSDictionary *param = @{@"timestamp":[NSString timeStr],@"sign":sign,@"token":token,@"password":self.NewPasswordsTextField.text,@"oldPassword":self.oldPasswordTextField.text};
        [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_CHANGPASSWORD parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
            if (error) {
                ZZCLog(@"失败-%@",error);
            }else {
                ZZCLog(@"-%@",responseObject);
                [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
                if ([responseObject[@"code"] isEqual:@(200)]) {
                    for (UIViewController *controller in self.navigationController.viewControllers) {
                        if ([controller isKindOfClass:[ZZCMeController class]]) {
                            [self.navigationController popToViewController:controller animated:YES];
                            //这里可以做回到登录界面的一些数据操作
                        }
                    }
                }
            }
        }];

    }else {
        [UIAlertController showInfoAlertLoginVC:self title:@"提示" message:@"两次输入的密码不一样" ok:nil];
    }
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
@end
